package net.projecteuler.prob;

public class Problem44 implements Runnable {

	@Override
	public void run() {		
		long[] pentaNum = new long[10000];
		for(int i = 0; i < 10000; i++){
			pentaNum[i] = (3 * i + 2) * (i + 1) / 2;
		}
		
		for(int i = 0; i < 10000; i++){
			for(int j = 0; j < i; j++){
				long Pj = pentaNum[i];
				long Pk = pentaNum[j];
				long sum = Pj + Pk;
				long diff = Pj - Pk;
				
				if(isPentaNum(sum) && isPentaNum(diff)){
					System.out.println(Pj + " - " + Pk + " = " + diff);
				}
			}
		}
	}
	
	private boolean isPentaNum(long value){
		double test = (Math.sqrt(24.0 * (double)value + 1.0) + 1.0) / 6.0;
		if(Math.abs(test - Math.round(test)) == 0.0){
			return true;
		}
		return false;
	}

}
